#include <stdio.h>
#include "list.h"

void INIT_LIST(LIST *list) {
	if(!list) return;

	NODE *node = &list->node;
	node->prev = node;
	node->next = node;

	list->size = 0;
}


static inline void __list_add(NODE *new_node, NODE *prev_node, NODE *next_node) {
    prev_node->next = new_node;
    new_node->prev  = prev_node;
    new_node->next  = next_node;
	next_node->prev = new_node;
}

void list_add(NODE *new_node, NODE *head_node) {
	if((!new_node) || (!head_node)) return;
	__list_add(new_node, head_node->prev, head_node);
}


static inline void __list_del(NODE * prev_node, NODE * next_node) {
    prev_node->next = next_node;
	next_node->prev = prev_node;
}

void list_del(NODE *node) {
	__list_del(node->prev, node->next);
    node->prev = NULL;
	node->next = NULL;
}
